package com.loongtech.bi.manager.realTime;

import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Service;

import com.loongtech.bi.entity.realTime.EntityNewUserByQuantum;
import com.loongtech.core.jpa.manager.ManagerQueryCacheBase;
import com.loongtech.core.util.Time;

/**
 * 
 * @author marin
 * @date 2015-09-15
 */
@Service
public class NewUserByQuantumManager extends ManagerQueryCacheBase<EntityNewUserByQuantum> {
	private static final long serialVersionUID = 1L;
	
	public List<EntityNewUserByQuantum> getNewUserRealTimeDatasByServers(Date lookDate, List<String> servers) {
		if (servers == null || servers.size() <= 0) {
			return null;
		}
		
		return findByQuery("from EntityNewUserByQuantum where day=:dayStart and platformid=:platformid and channelid=:channelid and serverid in (:serverid)", "dayStart", new Date(Time.getBeginningOfDay(lookDate.getTime())), "platformid", "0", "channelid", "0", "serverid", servers);
	}
	
	/*public List<Object[]> getAllNewUserRealTimeDatas(Date lookDate) {
		return findByQuery("select a.serverid,a.new_user from EntityNewUserByQuantum as a where a.day=:dayStart and a.platformid=:platformid and a.channelid=:channelid and a.serverid != :serverid and a.quantum = (select max(quantum) from EntityNewUserByQuantum where day=:dayStart and platformid=:platformid and channelid=:channelid and serverid != :serverid and a.serverid=serverid and a.quantum=quantum)", "dayStart", new Date(Time.getBeginningOfDay(lookDate.getTime())), "platformid", "0", "channelid", "0", "serverid", "0");
	}*/
	
	public List<Object[]> getAllNewUserRealTimeDatas(Date lookDate) {
		return findByQuery("select serverid,sum(new_user) from EntityNewUserByQuantum where day=:dayStart and platformid=:platformid and channelid=:channelid and serverid != :serverid group by serverid", "dayStart", new Date(Time.getBeginningOfDay(lookDate.getTime())), "platformid", "0", "channelid", "0", "serverid", "0");
	}
}
